/**
 * Copyright &copy; 2016-2017 <a href="http://git.oschina.net/whoamien/backend_management">Backend Management</a> All rights reserved.
 */
package com.xw.app.generator.vo;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xw.app.generator.util.DataTypeUtil;
import com.xw.util.JsonUtil;
import com.xw.util.StringUtil;

/**
 * The Class KeyColumn.
 *
 * @author Xi Wei
 */
public class KeyColumn implements Serializable{

	private String constraintName                    ;
	private String tableName                         ;
	private String columnName                        ;
	private String referencedTableName              ;
	private String referencedColumnName             ;
	
	@JsonIgnore
	private Column column;
	@JsonIgnore
	private Column referencedColumn;
	
	@JsonIgnore
	private List<Column> referencedColumnList;
	
	private String referencedDisplayName;//外键在页面上显示的属性
	
	/**
	 * Gets the constraint name.
	 *
	 * @return the constraint name
	 */
	public String getConstraintName() {
		return constraintName;
	}
	
	/**
	 * Sets the constraint name.
	 *
	 * @param constraintName the new constraint name
	 */
	public void setConstraintName(String constraintName) {
		this.constraintName = constraintName;
	}
	
	/**
	 * Gets the table name.
	 *
	 * @return the table name
	 */
	public String getTableName() {
		return tableName;
	}
	
	/**
	 * Sets the table name.
	 *
	 * @param tableName the new table name
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	
	/**
	 * Gets the column name.
	 *
	 * @return the column name
	 */
	public String getColumnName() {
		return columnName;
	}
	
	/**
	 * Sets the column name.
	 *
	 * @param columnName the new column name
	 */
	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}
	
	/**
	 * Gets the referenced table name.
	 *
	 * @return the referenced table name
	 */
	public String getReferencedTableName() {
		return referencedTableName;
	}
	
	/**
	 * Sets the referenced table name.
	 *
	 * @param referencedTableName the new referenced table name
	 */
	public void setReferencedTableName(String referencedTableName) {
		this.referencedTableName = referencedTableName;
	}
	
	/**
	 * Gets the referenced column name.
	 *
	 * @return the referenced column name
	 */
	public String getReferencedColumnName() {
		return referencedColumnName;
	}
	
	/**
	 * Sets the referenced column name.
	 *
	 * @param referencedColumnName the new referenced column name
	 */
	public void setReferencedColumnName(String referencedColumnName) {
		this.referencedColumnName = referencedColumnName;
	}
	
	/**
	 * Gets the referenced display name.
	 *
	 * @return the referenced display name
	 */
	public String getReferencedDisplayName() {
		return referencedDisplayName;
	}
	
	/**
	 * Sets the referenced display name.
	 *
	 * @param referencedDisplayName the new referenced display name
	 */
	public void setReferencedDisplayName(String referencedDisplayName) {
		this.referencedDisplayName = referencedDisplayName;
	}
	
	/**
	 * Gets the referenced column list.
	 *
	 * @return the referenced column list
	 */
	public List<Column> getReferencedColumnList() {
		return referencedColumnList;
	}
	
	/**
	 * Sets the referenced column list.
	 *
	 * @param referencedColumnList the new referenced column list
	 */
	public void setReferencedColumnList(List<Column> referencedColumnList) {
		this.referencedColumnList = referencedColumnList;
	}
		
	
	/**
	 * Gets the column.
	 *
	 * @return the column
	 */
	public Column getColumn() {
		return column;
	}
	
	/**
	 * Sets the column.
	 *
	 * @param column the new column
	 */
	public void setColumn(Column column) {
		this.column = column;
	}
	
	/**
	 * Gets the referenced column.
	 *
	 * @return the referenced column
	 */
	public Column getReferencedColumn() {
		return referencedColumn;
	}
	
	/**
	 * Sets the referenced column.
	 *
	 * @param referencedColumn the new referenced column
	 */
	public void setReferencedColumn(Column referencedColumn) {
		this.referencedColumn = referencedColumn;
	}
	
	/**
	 * Gets the referenced table java field.
	 *
	 * @return the referenced table java field
	 */
	public String getReferencedTableJavaField(){
		return StringUtil.toCamelCase(referencedTableName);
	}
	
	/**
	 * Gets the referenced column type.
	 *
	 * @return the referenced column type
	 */
	public String getReferencedColumnType(){
		return referencedColumn.getJavaType();
	}
	
	
	
	/////////////////
	/**
	 * parent_id -> parent
	 * scenic_spot_id -> scenicSpot.
	 *
	 * @return the column name java field
	 */
	public String getColumnNameJavaField(){
		String javaField = StringUtil.toCamelCase(getColumnName());
		if(javaField.toLowerCase().endsWith("id") || javaField.toLowerCase().endsWith("no")){
			return javaField.substring(0,javaField.length() - 2);
		}
		return javaField;
	}
	
	/**
	 * Gets the reference column java field.
	 *
	 * @return the reference column java field
	 */
	public String getReferenceColumnJavaField(){
		return StringUtil.toCamelCase(getReferencedColumnName());
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return JsonUtil.beanToJson(this);
	}

}
